package org.example;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class Tools {

    public static String getResourcePath() {
        return getResourcePath("/", true);
    }

    public static String getResourcePath(String name) {
        return getResourcePath(name, true);
    }

    public static String getResourcePath(String name, boolean urlDecode) {
        var path = Tools.class.getResource(name).toString();
        try {
            URL url = new URL(path);
            path = url.getFile();
        } catch (MalformedURLException e) {
            return "";
        }

        if (urlDecode) {
            return java.net.URLDecoder.decode(path, StandardCharsets.UTF_8);
        } else {
            return path;
        }
    }

}



